package com.zzyl.nursing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.DoTaskDTO;
import com.zzyl.nursing.dto.UpdateTimeDTO;
import com.zzyl.nursing.vo.NursingTaskVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 护理任务Mapper接口
 *
 * @author alexis
 * @date 2024-11-17
 */
@Mapper
public interface NursingTaskMapper extends BaseMapper<NursingTask> {
    /**
     * 查询护理任务
     *
     * @param id 护理任务主键
     * @return 护理任务
     */
    public NursingTask selectNursingTaskById(Long id);

    /**
     * 查询护理任务列表
     *
     * @param nursingTask 护理任务
     * @return 护理任务集合
     */
    public List<NursingTaskVo> selectNursingTaskList(NursingTask nursingTask);

    /**
     * 新增护理任务
     *
     * @param nursingTask 护理任务
     * @return 结果
     */
    public int insertNursingTask(NursingTask nursingTask);

    /**
     * 修改护理任务
     *
     * @param nursingTask 护理任务
     * @return 结果
     */
    public int updateNursingTask(NursingTask nursingTask);

    /**
     * 删除护理任务
     *
     * @param id 护理任务主键
     * @return 结果
     */
    public int deleteNursingTaskById(Long id);

    /**
     * 批量删除护理任务
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteNursingTaskByIds(Long[] ids);

    /**
     * 取消任务
     *
     * @param reason
     * @param taskId
     * @return
     */
    @Update("update nursing_task set status = 3, cancel_reason = #{reason}, update_time = now()" +
            ",update_by = #{userId} where id = #{taskId}")
    int cancel(@Param("reason") String reason, @Param("taskId") Long taskId, @Param("userId") Long userId);

    @Update("update nursing_task set estimated_server_time = #{estimatedServerTime}," +
            "update_time = now(), update_by = #{userId} where id = #{taskId}")
    int updateTime(UpdateTimeDTO updateTimeDTO);

    /**
     * 任务执行
     *
     * @param doTaskDTO
     * @return
     */
    @Update("update nursing_task set estimated_server_time = #{estimatedServerTime}, mark = #{mark}, real_server_time = now()," +
            "update_time = now() , update_by = #{userId} , status= 2,  task_image = #{taskImage} where id = #{taskId}")
    int doTask(DoTaskDTO doTaskDTO);


    String getUpdaterName(@Param("updateBy") Long updateBy);
}
